package cn.chinaunicom.sdsi.upfc_demp.demo.controller;

import cn.chinaunicom.sdsi.upfc_demp.demo.entity.UpfDemoTest;
import cn.chinaunicom.sdsi.upfc_demp.demo.service.UpfDemoTestService;

import cn.chinaunicom.sdsi.frm.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.json.JSONObject;

/**
 * @author lij
 * 2017-5-3 11:21:59
 *
 */

@Controller
@RequestMapping("upfDemoTestController")
public class UpfDemoTestController extends BaseController{

	private final Log log = LogFactory.getLog(UpfDemoTestController.class);
	
	@Autowired
	private UpfDemoTestService upfDemoTestService;

	/**
	 * 跳转至查询页面
	 */
	@RequestMapping("/upfDemoTestControllerMain")
	public ModelAndView upfDemoTestControllerMain(ModelAndView mv){
		log.debug("UpfDemoTestController.upfDemoTestControllerMain{}");
		mv.setViewName("demo/demotest/upfDemoTestList");
		return mv;
	}
	
	/**
	 * 跳转至新增页面
	 */
	@RequestMapping("/showAddPage")
	public ModelAndView showAddPage(ModelAndView mv){
		mv.setViewName("demo/demotest/upfDemoTestAdd");
		return mv;
	}
	
	/**
	 * 分页查询
	 * @param start 开始条数,名称不可改变，参数为分页组件传入
	 * @param length 每页大小,名称不可改变，参数为分页组件传入
	 */
	@ResponseBody
	@RequestMapping("/search4PageList")
	public JSONObject search4PageList(UpfDemoTest upfDemoTest,Integer start, Integer length){
		
		log.debug("UpfDemoTestController.search4PageList{}");
		return upfDemoTestService.search4PageList(upfDemoTest,start,length);
	}
	
	/**
	 * 查询单条数据
	 */
	@RequestMapping("/selectByPrimaryKey")
	public ModelAndView selectByPrimaryKey(UpfDemoTest upfDemoTest,ModelAndView mv){
		
		log.debug("UpfDemoTestController.selectByPrimaryKey{}");
		UpfDemoTest bean=upfDemoTestService.selectByPrimaryKey(upfDemoTest);
		mv.addObject("bean",bean);
		mv.setViewName("demo/demotest/upfDemoTestUpdate");
		return mv;
	}
	
	/**
	 * 删除单条数据
	 */
	@ResponseBody
	@RequestMapping("/deleteByPrimaryKey")
	public int deleteByPrimaryKey(UpfDemoTest upfDemoTest){
		int delnum = upfDemoTestService.deleteByPrimaryKey(upfDemoTest);
		return delnum;
	}

	/**
	 * 保存数据
	 */
	@ResponseBody
	@RequestMapping("/addObject")
	public int addObject(UpfDemoTest upfDemoTest){
		int insertnum = upfDemoTestService.addObject(upfDemoTest);
		return insertnum;
	}

	/**
	 * 修改单条数据
	 */
	@ResponseBody
	@RequestMapping("/updateByPrimaryKey")
	public int updateByPrimaryKey(UpfDemoTest upfDemoTest){
		int updatetnum = upfDemoTestService.updateByPrimaryKey(upfDemoTest);
		return updatetnum;
	}
}